#ifndef W25QXX_H
#define W25QXX_H

#include "spi.h"
#include "sx127x.h"

#define W25QXX_CS_PORT  gpioPortC
#define W25QXX_CS_PIN   5

#define W25QXX_CS_PIN_WRITE(value) (value > 0)?GPIO_PinOutSet(W25QXX_CS_PORT, W25QXX_CS_PIN):GPIO_PinOutClear(W25QXX_CS_PORT, W25QXX_CS_PIN)

#define W25Q80 	                      0xEF13 	
#define W25Q16 	                      0xEF14
#define W25Q32 	                      0xEF15
#define W25Q64 	                      0xEF16
#define W25Q128	                      0xEF17  

#define READ_DATA                     0x03       
#define HIGH_SPEED_READ_DATA          0x0B    
#define SECTOR_ERASE_4KB              0x20     
#define BLOCK_ERASE_32KB              0x52       
#define BLOCK_ERASE_64KB              0xD8       
#define CHIP_ERASE                    0xC7     

#define PAGE_PROGRAM                  0x02    
#define READ_STATUS_REG               0x05       
#define ENABLE_WRITE_STATUS_REG       0x50
#define WRITE_STATUS_REG              0x01      

#define W25X_POWER_DOWN			      0xB9 
#define W25X_WAKE_UP	              0xAB 

#define WRITE_ENABLE                  0x06      
#define WRITE_DISABLE                 0x04      
#define READ_DEVICE_ID                0x90      

#define READ_JEDEC_ID                 0x9F     

#define EBSY                          0X70      
#define DBSY                          0X80     


uint8_t w25qxx_init(void);
void w25qxx_disable(void);
void w25qxx_read(uint8_t *cbuf, uint32_t addr, uint16_t csize);
void w25qxx_write(uint8_t *cbuf, uint32_t addr, uint16_t csize);
void w25qxx_write_page(uint8_t *cbuf, uint32_t addr, uint16_t csize);
uint16_t w25qxx_read_id(void);
uint8_t w25qxx_read_sr(void);
void w25qxx_write_sr(uint8_t sr);
void w25qxx_write_enable(void);
void w25qxx_write_disable(void);
void w25qxx_wait_busy(void);
void w25qxx_erase_chip(void);
void w25qxx_erase_sector(uint32_t addr);
void w25qxx_power_down(void);
void w25qxx_wake_up(void);

#endif 
